package com.csii.adhoc.controller.info;

import com.csii.adhoc.annotation.OperationLog;
import com.csii.adhoc.info.role.RoleVo;
import com.csii.adhoc.info.role.service.RoleService;
import com.csii.adhoc.util.DateUtils;
import com.csii.result.APIResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @description: 角色控制层
 * @author: panChuanJiang
 * @create: 2021-01-27 16:57
 */
@RestController
@Slf4j
@RequestMapping("/role")
public class RoleController {
    @Resource
    private RoleService roleService;

    @RequestMapping("roleMaintain")
    @OperationLog("角色维护")
    public APIResult roleMaintain(@RequestBody RoleVo roleVo) {
        String userId = Optional.ofNullable(String.valueOf(SecurityUtils.getSubject().getPrincipal())).orElse("未知用户");
        roleVo.setUpdatedBy(userId)
                .setUpdatedDt(DateUtils.getDateString("yyyyMMddHHmmss"));
        roleService.roleMaintain(roleVo, roleVo.getOptMode());
        return APIResult.successResult(null);
    }

    @RequestMapping("roleQuery")
    public APIResult roleQuery(@RequestBody(required = false) RoleVo roleVo) {
        return APIResult.successResult(roleService.selectListRole(roleVo));
    }
}
